﻿using System;
using HslCommunication.Profinet.Melsec;

namespace HslCommunication.Core.Address
{
	/// <summary>
	/// 三菱R系列的PLC的地址表示对象
	/// </summary>
	// Token: 0x02000169 RID: 361
	public class McRAddressData : DeviceAddressDataBase
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x06001DEE RID: 7662 RVA: 0x0008E7A5 File Offset: 0x0008C9A5
		public McRAddressData()
		{
			this.McDataType = MelsecMcRDataType.D;
		}

		/// <summary>
		/// 三菱的数据类型及地址信息
		/// </summary>
		// Token: 0x1700061A RID: 1562
		// (get) Token: 0x06001DEF RID: 7663 RVA: 0x0008E7BB File Offset: 0x0008C9BB
		// (set) Token: 0x06001DF0 RID: 7664 RVA: 0x0008E7C3 File Offset: 0x0008C9C3
		public MelsecMcRDataType McDataType { get; set; }

		/// <summary>
		/// 从指定的地址信息解析成真正的设备地址信息，默认是三菱的地址
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		// Token: 0x06001DF1 RID: 7665 RVA: 0x0008E7CC File Offset: 0x0008C9CC
		public override void Parse(string address, ushort length)
		{
			OperateResult<McRAddressData> operateResult = McRAddressData.ParseMelsecRFrom(address, length);
			bool isSuccess = operateResult.IsSuccess;
			if (isSuccess)
			{
				base.AddressStart = operateResult.Content.AddressStart;
				base.Length = operateResult.Content.Length;
				this.McDataType = operateResult.Content.McDataType;
			}
		}

		/// <summary>
		/// 解析出三菱R系列的地址信息
		/// </summary>
		/// <param name="address">三菱的地址信息</param>
		/// <param name="length">读取的长度，对写入无效</param>
		/// <returns>解析结果</returns>
		// Token: 0x06001DF2 RID: 7666 RVA: 0x0008E824 File Offset: 0x0008CA24
		public static OperateResult<McRAddressData> ParseMelsecRFrom(string address, ushort length)
		{
			OperateResult<MelsecMcRDataType, int> operateResult = MelsecMcRNet.AnalysisAddress(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<McRAddressData> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<McRAddressData>(operateResult);
			}
			else
			{
				result = OperateResult.CreateSuccessResult<McRAddressData>(new McRAddressData
				{
					McDataType = operateResult.Content1,
					AddressStart = operateResult.Content2,
					Length = length
				});
			}
			return result;
		}
	}
}
